#! /usr/bin/env python3
from PIL import Image
from glob import glob
import os
from tqdm import tqdm
import argparse

def resizeImages(dir1, dir2, size):
    pathList = glob(os.path.join(dir1, '*'))
    for i in tqdm(range(len(pathList)), ncols=100):
        path1 = pathList[i]
        filename = os.path.split(path1)[-1]
        path2 = os.path.join(dir2, filename)
        image1 = Image.open(path1).convert('RGB')
        image2 = image1.resize(size, resample=Image.BOX)
        image2.save(path2)

if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='图片（下）采样工具')
    parser.add_argument('source', metavar='原始图片目录', type=str,
                        help='原始图片文件所在目录')
    parser.add_argument('designation', metavar='生成图片目录', type=str,
                        help='生成图片文件所在目录')
    parser.add_argument('-s', dest='size', type=int, default=64,
                        help='图片缩放尺寸，默认 64×64')

    args = parser.parse_args()
    resizeImages(args.source, args.designation, (args.size, args.size))
